package Review;


public class Test2 {
    //逆序打印数组第二种方案
    public static void main(String[] args) {
        int[] arr = new int[]{1,3,5,2,4,6};
        dfs3(arr,0);
    }
    //逆序打印数组
    public static void main2(String[] args) {
        int[] arr = new int[]{1,3,5,2,4,6};
        dfs2(arr,arr.length-1);
    }
    //递归打印数组
    public static void main1(String[] args) {
        int[] arr = new int[]{1,3,5,2,4,6};
        dfs(arr,0);
    }
    public static void dfs(int[] arr,int n){
        if(n == arr.length) return;
        System.out.print(arr[n]+" ");
        dfs(arr,n+1);
    }
    //逆序打印方法1
    public static void dfs2(int[] arr,int n){
        if(n == -1) return;
        System.out.print(arr[n]+" ");
        dfs2(arr,n-1);
    }
    //逆序打印方法2
    public static void dfs3(int[] arr,int n){
        if(n == arr.length) return;
        //下面两行逻辑交换顺序即可
        dfs3(arr,n+1);
        System.out.print(arr[n]+" ");

    }
}
